package youleche.com.business;

import java.sql.Connection;
import java.util.List;

import youleche.com.common.IDFactory;
import youleche.com.connection.ConnectionFactory;
import youleche.com.factory.DaoFactory;
import youleche.com.idao.IBaseParamInfo;
import youleche.com.model.MBaseParamInfo;


/**
 * 基础参数业务
 * @author Administrator
 *
 */
public class BBaseParamInfo {
	/**
	 * 连接
	 */
	private Connection con = null;
	
	/**
	 * 基础参数信息处理类
	 */
	private IBaseParamInfo infoHandler = null;
	
	/**
	 * 构造函数
	 */
	public BBaseParamInfo(){
		this.infoHandler = DaoFactory.getDBaseParamInfo();
	}
	
	/**
	 * 获取基础参数列表
	 * @param con 数据库连接
	 * @return 返回基础参数列表
	 * @throws Exception 抛出异常
	 */
	public List<MBaseParamInfo> getBaseParamInfoList() throws Exception{
		try{
			this.con = ConnectionFactory.getUlecheReadConnection();
			return this.infoHandler.getBaseParamInfoList(this.con);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
	
	/**
	 * 添加基础信息
	 * @param model 添加对象
	 * @return 返回添加影响的行数
	 * @throws Exception 异常
	 */
	public int addBaseParamInfo(MBaseParamInfo model)
			throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheWriteConnection();
			model.setKeyID(IDFactory.getId("youleche", "baseparaminfo"));
			return this.infoHandler.addBaseParamInfo(this.con, model);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
	
	/**
	 * 得到keyId通过值和name
	 * @param paramValue 参数值
	 * @param paramName 参数名
	 * @return keyId
	 * @throws Exception 异常
	 */
	public String getKeyIdByParamValueAndName(
			String paramValue, String paramName) throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheReadConnection();
			return this.infoHandler.getKeyIdByParamValueAndName(this.con, paramValue, paramName);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
	
	/**
	 * 更新基础参数
	 * @param info 基础参数
	 * @return 返回更新影响的行数
	 * @throws Exception 异常
	 */
	public int updateBaseInfobyKeyId(MBaseParamInfo info)
			throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheWriteConnection();
			return this.infoHandler.updateBaseInfobyKeyId(this.con, info);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
}
	
